var t = getApp(), a = void 0;

Page({
    data: {
        api: t.com.API
    },
    onLoad: function(t) {
        (a = this).getMsg(), a.checkVip();
    },
    getCoupon: function(a) {
        var e = a.currentTarget.dataset.id, n = a.currentTarget.dataset.type;
        this.data.vip ? (wx.showLoading({
            title: "获取中"
        }), t.com.post("wx/coupon/vipDraw", {
            couponId: e,
            dayType: n
        }, function(t) {
            wx.hideLoading(), 0 === t.errno && wx.showToast({
                title: t.errmsg
            });
        })) : wx.showToast({
            title: "您还不是会员哦",
            icon: "none"
        });
    },
    getMsg: function() {
        t.com.post("wx/config/vip", {}, function(t) {
            0 === t.errno && a.setData(t.data);
        });
    },
    checkVip: function() {
        t.com.post("wx/vip/check", {}, function(t) {
            0 === t.errno && a.setData({
                vip: t.data
            });
        });
    },
    openVip: function(e) {
        var n = e.currentTarget.dataset.type, o = e.currentTarget.dataset.name;
        wx.showModal({
            title: "提示",
            content: "您选择的是" + o + ",请您确认后点击开通。",
            confirmText: "立即开通",
            success: function(e) {
                e.confirm && t.com.post("wx/vip/buy", {
                    buyType: n
                }, function(t) {
                    wx.requestPayment({
                        timeStamp: t.data.timestamp,
                        nonceStr: t.data.nonceStr,
                        package: t.data.package,
                        signType: "MD5",
                        paySign: t.data.paySign,
                        success: function(t) {
                            wx.showToast({
                                title: "支付成功",
                                duration: 2e3,
                                mask: !0
                            }), setTimeout(function() {
                                a.checkVip();
                            }, 2e3);
                        },
                        fail: function(t) {}
                    });
                });
            }
        });
    }
});